package 二分查找;

import java.util.Arrays;

public class LeetCode1385_两个数组间的距离值 {
    public int findTheDistanceValue(int[] arr1, int[] arr2, int d) {
        Arrays.sort(arr2);
        int ans = 0;
        for (int i1 : arr1) {
            int low = i1 - d;
            int high = i1 + d;
            int index1 = Arrays.binarySearch(arr2, low);
            int index2 = Arrays.binarySearch(arr2, high);
            if (index1 < 0 && index1 == index2) {
                ans++;
            }
        }
        return ans;
    }
}
